<template>
  <div>
    <div>
      <span class="padding-l-sm" :style="{color:tempColor}">
        {{ customerName }}
      </span>
    </div>
    <div>
      <span class="padding-l-sm">
        {{ customerCode }} <img v-if="icon" :src="icon" style="height:12px" />
      </span>
    </div>
    <div v-if="customerSpecial!=null&&customerSpecial!=''">
    <el-tooltip effect="light" placement="left">
      <div slot="content">
        <div
          v-html="customerSpecial"
          style="max-width:500px;overflow:auto;background: #e1e5e8;font-size: 15px;line-height: 16px;color: #888;max-height: 320px;"
        ></div>
      </div>
      <template v-if="temp==1">
        <img :src ="specialPng" @click="findSpecial"/>
      </template>
<!--      <i-->
<!--        style="font-size:20px"-->
<!--        class="el-icon-info"-->
<!--      ></i>-->
    </el-tooltip>
    </div>
  </div>
</template>

<script>
import vipPng from "@/assets/images/vip_icon.png";
import svipPng from "@/assets/images/svip_icon.png";
import specialPng from "@/assets/images/special-1.png";
import {ajax} from "../../../../../store/yg/common/utils";
export default {
  props: ["row", "data", "more"],
  data() {
    return {
      customerId: "",
      icon: "",
      tempColor:"",
      customerName: "",
      customerCode: "",
      temp:0,
      specialPng:specialPng,
      codeMap: {},
      nameMap: {},
      levelMap: {},
      deliverTime:"",
      customerDeliverTimeMap:{},
      customerSpecial:"",
    };
  },
  mounted() {
    this.initShow();
    this.initSpecial();

  },
  methods: {
    findSpecial(){
      var shippingWay=this.data.shippingWay;
     var countryIds=this.data.countryId;
      if (shippingWay=="99"){
        console.log("快递")
        shippingWay="EXPRESS"
      }
      if (shippingWay=="LCL"||shippingWay=="FCL"||shippingWay=="LCLG"||shippingWay=="FCLG"){
        console.log("海运")
        shippingWay="OCEAN"
      }
      if (shippingWay=="AIR"||shippingWay=="ZX"){
        console.log("空运")
        shippingWay="AIRLIFT"
      }
      let n = [
        {
          field: "shippingWay",
          value: shippingWay,
        },
        {
          field:"countryIds",
          value: countryIds,
        }
      ];
      let node = JSON.stringify(n);
      console.log("参数",node)
      window.open("/#/main/setting__customerspecialscenecontent__list?node="+node,
        "_blank");
    },
    initShow() {
      var customerId = this.data["customerId"];
      this.nameMap = this.$store.state.main.entry.sources[
        "customerNameShortSource"
      ];
      this.customerDeliverTimeMap=this.$store.state.main.entry.sources["customerDeliverTimeSource"];
      this.codeMap = this.$store.state.main.entry.sources["customerCodeSource"];
      this.levelMap = this.$store.state.main.entry.sources[
        "customerLevelAllSource"
      ];
      if (this.nameMap) {
        this.customerName = this.nameMap[customerId];
      }
      if (this.codeMap) {
        this.customerCode = this.codeMap[customerId];
      }
      if (this.customerDeliverTimeMap){
       var deliverTime=this.customerDeliverTimeMap[customerId];
       if(deliverTime){
         var g = new Date().getTime();//1637120820767
         var time = new Date(g); //创建一个指定的日期对象
         console.log(time);
         console.log(this.formatDate(time));
      var dateDiff= this.difference(deliverTime,time);
        if (dateDiff<=365){
        this.tempColor="#33FF00"
        }else{
          this.tempColor="black"
        }
       }
      }

      if (this.levelMap) {
        var level = this.levelMap[customerId];
        if (level == 10) {
          this.icon = svipPng;
        } else if (level == 20) {
          this.icon = vipPng;
        }
      }
    },
    difference: function (beginTime, endTime) {
      var dateBegin = new Date(beginTime);
      var dateEnd = new Date(endTime);
      var dateDiff = dateEnd.getTime() - dateBegin.getTime(); //时间差的毫秒数
      var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
      var leave1 = dateDiff % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
      var hours = Math.floor(leave1 / (3600 * 1000)); //计算出小时数
      //计算相差分钟数
      var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
      var minutes = Math.floor(leave2 / (60 * 1000)); //计算相差分钟数
      //计算相差秒数
      var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
      var seconds = Math.round(leave3 / 1000);
      console.log(
        "相差" +
        dayDiff +
        "天" +
        hours +
        "小时" +
        minutes +
        "分钟" +
        seconds +
        "秒"
      );
      return dayDiff;
    },
    formatDate(now) {
      var year = now.getFullYear(); //取得4位数的年份
      var month = now.getMonth() + 1; //取得日期中的月份，其中0表示1月，11表示12月
      var date = now.getDate(); //返回日期月份中的天数（1到31）
      var hour = now.getHours(); //返回日期中的小时数（0到23）
      var minute = now.getMinutes(); //返回日期中的分钟数（0到59）
      var second = now.getSeconds(); //返回日期中的秒数（0到59）
      return (
        year +
        "-" +
        month +
        "-" +
        date +
        " " +
        hour +
        ":" +
        minute +
        ":" +
        second
      );
    },
    initSpecial(){
      var params = {};
      params["customerId"]=this.data["customerId"];
      params["shippingWay"]=this.data["shippingWay"];
      params["countryId"]=this.data["countryId"];
      ajax("findSpecialAll", params).then(
        res => {
          if (res.code == 200) {
            this.temp=1;
            this.customerSpecial = res.data;
          }
        },
        error => {
          console.log(error);
        }
      );

    }
  }
};
</script>

<style>
.top {
  text-align: center;
}
</style>
